﻿using UnityEditor;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.StreetEvent.Editor
{
    [CustomEditor(typeof(StreetEventBase))]
    public class StreetEventBaseEditor : UnityEditor.Editor
    {
        SerializedProperty OpenNpcRespawnProperty;
        SerializedProperty RebornTimeProperty;
        SerializedProperty DaddyTimeProperty;
        void OnEnable()
        {
            // 获取属性引用
            OpenNpcRespawnProperty = serializedObject.FindProperty("OpenNpcRespawn");
            RebornTimeProperty = serializedObject.FindProperty("rebornTime");
            DaddyTimeProperty = serializedObject.FindProperty("baddyTime");
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            
            StreetEventBase streetEvent = target as StreetEventBase;

            if (GUILayout.Button("显示点"))
            {
                streetEvent.eventConfig.SwitchPointShower(true);
            }

            if (GUILayout.Button("隐藏点"))
            {
                streetEvent.eventConfig.SwitchPointShower(false);
            }
            // 始终显示布尔属性
            EditorGUILayout.PropertyField(OpenNpcRespawnProperty);

            // 当布尔属性为true时，显示目标属性
            if (OpenNpcRespawnProperty.boolValue)
            {
                EditorGUILayout.PropertyField(RebornTimeProperty);
                EditorGUILayout.PropertyField(DaddyTimeProperty);
            }
            serializedObject.ApplyModifiedProperties();
          
            base.OnInspectorGUI();
        }
    }
}